/**
 * Created by lobin on 2017/7/24.
 */
import { Application } from 'egg';
import * as pageFindPlugin from 'mongoose-paginate';
export default (app: Application) => {
  const mongoose = app.mongoose;
  const schema = new mongoose.Schema({
    code: { type: String , required: false },
    partner: { type: String, required: false, ref: 'Partner' },
    openid: { type: String, required: false },
    site: { type: String, required: true, ref: 'Site' },
    ordertype: { type: String },
    money: { type: Number, required: true , default: 0 },
    cost: { type: Number },
    paytype: { type: String },
    GoodsName: { type: String, default: '生活用品' },
    GoodsWeight: { type: String, required: true, default: 1 },
    SenderName: { type: String, required: false },
    id: { type: String, required: false },
    Senderarea: { type: Array, required: false },
    SenderAddress: { type: String, required: false },
    SenderMobile: { type: String, required: false },
    ReceiverName: { type: String, required: false },
    Receiverarea: { type: Array, required: false },
    ReceiverAddress: { type: String, required: false },
    ReceiverMobile: { type: String, required: false },
    user: { type: String, required: true },
    desc: { type: String, required: true, default: '在线订单' },
    serial: {
      type: String, required: true,
    },
    ctime: {
      type: String,
      required: true,
    },
    ispay: { type: Boolean },
    status: { type: String, required: true, default: '0' },
    logs: [],
  }, {
        id: false,
        toJSON: {
        getters: true,
        virtuals: true,
        },
  });
  // tslint:disable-next-line:ter-prefer-arrow-callback
  schema.virtual('profit').get(function (this: any) {
    return this.money - this.cost;
  });
  schema.plugin(pageFindPlugin, {});
  return mongoose.model('Delivery', schema, 'delivery');
};
